package com.atgouwu.aiparent.springaialibaba.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Spring AI集成多个大语言模型，OpenAI，DeepSeek，Qwen，协议适配
 */
@RestController
@RequestMapping("/ai")
public class AiController {
    private final ChatClient openAiChatClient;
    private final ChatClient qwenChatClient;
    private final ChatClient deepseekChatClient;
    public AiController(
            @Qualifier("openAiChatClientBuilder") ChatClient.Builder openAiChatClientBuilder,
            @Qualifier("qwenChatClientBuilder") ChatClient.Builder qwenChatClientBuilder,
            @Qualifier("deepseekChatClientBuilder") ChatClient.Builder deepseekChatClientBuilder) {
        this.openAiChatClient = openAiChatClientBuilder.build();
        this.qwenChatClient = qwenChatClientBuilder.build();
        this.deepseekChatClient = deepseekChatClientBuilder.build();
    }

    /**
     * http://localhost:9002/ai/openAiChat?prompt=介绍一下你自己
     */
    @GetMapping("/openAiChat")
    public String openAiChat(@RequestParam String message) {
        return openAiChatClient.prompt()
                .user(message)  //用户消息
                .call()  //同步调用
                .content();  //直接获取响应内容（字符串）
    }

    /**
     * http://localhost:9002/ai/qwenChat?prompt=介绍一下你自己
     */
    @GetMapping("/qwenChat")
    public String qwenChat(@RequestParam String message) {
        return qwenChatClient.prompt()
                .user(message)  //用户消息
                .call()  //同步调用
                .content();  //直接获取响应内容（字符串）
    }

    /**
     * http://localhost:9002/ai/deepseekChat?prompt=介绍一下你自己
     */
    @GetMapping("/deepseekChat")
    public String deepseekChat(@RequestParam String message) {
        return deepseekChatClient.prompt()
                .user(message)  //用户消息
                .call()  //同步调用
                .content();  //直接获取响应内容（字符串）
    }

}
